public class Student implements Comparable<Student> {
    
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student student) {
        // 根据年龄排序
        /*
         * 1. this.age > student.age 返回正数, this排在后面
         * 2. this.age < student.age 返回负数, this排在前面
         * 3. this.age == student.age 返回0, 位置不变
         */
        return this.age - student.age;
    }
}
